function mutil() {
    

}

// http://stackoverflow.com/questions/8273047/javascript-function-similar-to-python-range
mutil.prototype.range = function (start, stop, step) {
    if (typeof stop == 'undefined') {
        // one param defined
        stop = start;
        start = 0;
    }

    if (typeof step == 'undefined') {
        step = 1;
    }

    if ((step > 0 && start >= stop) || (step < 0 && start <= stop)) {
        return [];
    }

    var result = [];
    for (var i = start; step > 0 ? i < stop : i > stop; i += step) {
        result.push(i);
    }

    return result;
};

// http://stackoverflow.com/questions/5767325/how-to-remove-a-particular-element-from-an-array-in-javascript
mutil.prototype.remove = function(array, item)
{
    var index = array.indexOf(item);
    console.log("remove index", index);
    if(index > -1) {
        array.splice(index, 1);
    }
    return array;
}

mutil.prototype.randomSelect = function(array, chosenum)
{
    var result = [];
    while (result.length < chosenum) 
    {
        var tmpIndex = Math.floor(Math.random() * array.length)
        console.log("tmpIndex", tmpIndex);
        if(result.indexOf(array[tmpIndex]) > -1) continue;
        
        console.log("push", tmpIndex);
        result.push(array[tmpIndex]);
    }
    return result
}

module.exports = new mutil();
